package cn.tansanqinger.dao.sql.chatroom;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.tansanqinger.dao.sql.IFriendlistSqlDao;
import cn.tansanqinger.pojo.Friendlist;

@Repository
public class FriendlistSqlDaoImpl {

	@Autowired
	private IFriendlistSqlDao dao;
	
	/**
	 * 查询用户好友
	 * @param 
	 * @return
	 */
	public List<Friendlist> selectMessage(int id){
		QueryWrapper<Friendlist> queryWrapper = new QueryWrapper<Friendlist>();
		queryWrapper.lambda().eq(Friendlist::getFid, id);
		return dao.selectList(queryWrapper);
	}
	
	/**
	 * 查询用户好友
	 * @param 
	 * @return
	 */
	public List<Friendlist> selectAccountMessage(String account){
		QueryWrapper<Friendlist> queryWrapper = new QueryWrapper<Friendlist>();
		queryWrapper.lambda().eq(Friendlist::getIaccount, account);
		return dao.selectList(queryWrapper);
	}
	
	
	/**
	 * 添加信息
	 * @param course
	 * @return
	 */
	public int add(Friendlist object) {
		return dao.insert(object);
	}
	
	/**
	 * 查询信息
	 * @param cid
	 * @return
	 */
	public Friendlist selectOnt(int id) {
		return dao.selectById(id);
	}
	
	/**
	 * 删除信息
	 * @param cid
	 * @return
	 */
	public int deleteOne(int id) {
		return dao.deleteById(id);
	}
	
	/**
	 * 修改信息
	 * @param user
	 * @return
	 */
	public int modification(Friendlist object) {
		return dao.updateById(object);
	}
	
	/**
	 * 删除好友，相互删除数据
	 * @param id1
	 * @param id2
	 * @return
	 */
	public int deleteFriend(int id1, int id2) {
		QueryWrapper<Friendlist> queryWrapper = new QueryWrapper<Friendlist>();
		queryWrapper.lambda().eq(Friendlist::getUid, id1).eq(Friendlist::getIid, id2);
		dao.delete(queryWrapper);
		queryWrapper = new QueryWrapper<Friendlist>();
		queryWrapper.lambda().eq(Friendlist::getUid, id2).eq(Friendlist::getIid, id1);
		return dao.delete(queryWrapper);
	}
	
}
